﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Quanlytailieu : System.Web.UI.Page
{
    BUS_Document objD = new BUS_Document();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["TeacherLogin"] != null)
            {
                Hienthi();
            }
            else Response.Redirect("dangnhap.aspx?gv=1");
        }
    }
    public void Hienthi()
    {
        Page.Title = "Quản lý tài liệu";
        
        string teacherid = Session["username"].ToString();
        gvdocument.DataSource = objD.BUS_Document_getDataByTeacherid(teacherid);
        gvdocument.DataBind();
    }
    protected void btnxoa_Click(object sender, EventArgs e)
    {
        try
        {
            int count = 0;
            for (int i = 0; i < gvdocument.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvdocument.Rows[i].Cells[0].FindControl("chkChon");
                if (chk.Checked)
                {
                    count++;
                    int id = int.Parse(gvdocument.Rows[i].Cells[1].Text);
                    //lap danh sach xoa
                    objD.BUS_Document_addtodel(id);
                }
            }
            //tien hanh xoa
            if (count > 0)
            {
                if (objD.BUS_Document_del())
                {
                    Hienthi();
                }
                else
                {
                    Response.Write("<script>alert(\"Xóa không thành công\")</script>");
                }
            }
            else Response.Write("<script>alert(\"Bạn chưa chọn mục xóa\")</script>");

        }
        catch (Exception ex)
        {

            throw new Exception(ex.Message);
        }
    }
}